﻿namespace SLClient.Extension
{
    using System;
    using System.Text.RegularExpressions;

    public class Comm
    {
        public static DateTime ZeroTime = new DateTime(0x7b2, 1, 1, 0, 0, 0);

        public static bool ContainsTwoChars(string a)
        {
            int num2;
            bool[] flagArray = new bool[4];
            string str = a;
            for (num2 = 0; num2 < str.Length; num2++)
            {
                char c = str[num2];
                if (char.IsLower(c))
                {
                    flagArray[0] = true;
                }
                else if (char.IsUpper(c))
                {
                    flagArray[1] = true;
                }
                else if (char.IsDigit(c))
                {
                    flagArray[2] = true;
                }
                else
                {
                    flagArray[3] = true;
                }
            }
            int num = 0;
            bool[] flagArray2 = flagArray;
            for (num2 = 0; num2 < flagArray2.Length; num2++)
            {
                if (flagArray2[num2])
                {
                    num++;
                }
            }
            return (num >= 2);
        }

        public static bool IsFloat(string text)
        {
            return Regex.IsMatch(text, @"^[\d\.]+$");
        }

        public static bool IsFloatAll(string text)
        {
            return Regex.IsMatch(text, @"^\-?[\d\.]+$");
        }

        public static bool IsInt(string text)
        {
            return Regex.IsMatch(text, @"^\-?[\d]+$");
        }

        public static bool IsIP(string text)
        {
            return Regex.IsMatch(text, @"^\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}$");
        }

        public static bool IsSameCharInString(string data)
        {
            if (!string.IsNullOrWhiteSpace(data))
            {
                for (int i = 0; i < data.Length; i++)
                {
                    for (int j = i + 1; j < data.Length; j++)
                    {
                        if (data[i] == data[j])
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        public static bool IsWord(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return false;
            }
            return Regex.IsMatch(text, @"^\w+$");
        }

        public static string SortString(string data)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                return data;
            }
            char[] array = data.ToCharArray();
            Array.Sort<char>(array);
            return new string(array);
        }
    }
}

